package com.konsung.presenter.impl;

import com.konsung.bean.MeasureDataBean;
import com.konsung.bean.PatientBean;
import com.konsung.bean.RecordAllMeasureResult;
import com.konsung.greendaoUtil.GreenDaoManager;
import com.konsung.greendaoUtil.MeasureDataBeanDao;
import com.konsung.kslibrary.base.BasePresenter;
import com.konsung.presenter.HealthReportPresenter;
import com.konsung.ui.HealthReportActivity;
import com.konsung.util.UiUtils;
import com.konsung.util.constant.GlobalConstant;

import java.util.List;

/**
 * 逻辑实现类
 */

public class HealthReportPresenterImpl extends BasePresenter<HealthReportActivity> implements
        HealthReportPresenter.Presenter {

    @Override
    public PatientBean getCurrentPatient() {

        return UiUtils.getCurrent();
    }

    @Override
    public List<MeasureDataBean> getAllMeasureData(String uuid) {
        return GreenDaoManager.getMeasureDao(mvpView).queryBuilder()
                .where(MeasureDataBeanDao.Properties.Uuid.eq(uuid)).list();
    }

    @Override
    public void printReport(MeasureDataBean measureData, PatientBean patientBean) {

    }

    @Override
    public RecordAllMeasureResult getPrintResult(MeasureDataBean measureDataBean) {
        RecordAllMeasureResult result = new RecordAllMeasureResult();
        result.setPrintEcg(getMeasureFlag(measureDataBean.getEcgHr()));
        result.setPrintEcgReport(measureDataBean.getEcgIsMeasure());
        result.setPrintBloodOx(getMeasureFlag(measureDataBean.getSpo2Tred()));
        result.setPrintBloodPress(getMeasureFlag(measureDataBean.getNibpSys()));
        result.setPrintTemp(getMeasureFlag(measureDataBean.getIrtemp()));
        if (measureDataBean.getBloodgluBeforeMeal() != GlobalConstant.INVALID_DATA) {
            //餐前
            result.setPrintBloodGlu(getMeasureFlag(measureDataBean.getBloodgluBeforeMeal()));
        } else {
            //餐后
            result.setPrintBloodGlu(getMeasureFlag(measureDataBean.getBloodgluAfterMeal()));
        }
        result.setPrintUrint(getMeasureFlag(measureDataBean.getUrinertLeu()));
        result.setPrintUric(getMeasureFlag(measureDataBean.getUricacidTrend()));
        result.setPrintChol(getMeasureFlag(measureDataBean.getCholesterolTrend()));
        result.setPrintWbc(getMeasureFlag(measureDataBean.getBloodWbc()));
        result.setPrintHgb(getMeasureFlag(measureDataBean.getBloodHgb()));
        result.setPrintGhb(getMeasureFlag(measureDataBean.getGhbIFCC()));
        result.setPrintBloodFat(getMeasureFlag(measureDataBean.getBloodFatCho()));
        if (getMeasureFlag(measureDataBean.getHeight())
                || getMeasureFlag(measureDataBean.getWeight())) {
            result.setPrintBmi(true);
        }
        return result;
    }

    /**
     * 判断测量项是否测量
     * @param value 测量值
     * @return 是否测量，true代表已测
     */
    private boolean getMeasureFlag(int value) {
        return !(value == GlobalConstant.INVALID_DATA);
    }
}
